package com.tiecode.compiler.api.file;

/**
 * Created by Scave on 2024/9/26
 */
public abstract class TiecodeSource {
    public abstract String getName();
    public abstract long lastModified();
    public abstract String readContent();
    public abstract String getURI();
    public abstract String getPath();
    public abstract FileCategory getCategory();
    public abstract boolean isNameCompatible(String name, FileCategory category);

    public final int _getCategory() {
        return getCategory().nativeEnum;
    }

    public final boolean _isNameCompatible(String name, int nativeFileCategory) {
        FileCategory category = FileCategory.SOURCE;
        for (FileCategory item : FileCategory.values()) {
            if (item.nativeEnum == nativeFileCategory) {
                category = item;
            }
        }
        return isNameCompatible(name, category);
    }

    public enum FileCategory {
        SOURCE(NATIVE_SOURCE),
        IR(NATIVE_IR),
        BYTECODE(NATIVE_BYTECODE);
        final int nativeEnum;
        FileCategory(int nativeEnum) {
            this.nativeEnum = nativeEnum;
        }
    }

    private final static int NATIVE_SOURCE = 0;
    private final static int NATIVE_IR = 1;
    private final static int NATIVE_BYTECODE = 2;
}
